package com.ts.proj.controller;

import com.alibaba.fastjson.JSONArray;
import com.ts.base.controller.BaseController;
import com.ts.common.constant.ConsoleConstant;
import com.ts.proj.service.SystemButtonService;
import com.ts.proj.service.SystemRoleService;
import com.ts.util.JurisdictionUtil;
import com.ts.util.PageData;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;


@Controller
@Slf4j
public class SystemRoleController extends BaseController {

    @Autowired
    private SystemButtonService systemButtonService;

    @Autowired
    private SystemRoleService systemRoleService;

    /**
     * 管理员
     * @return
     */
    @RequestMapping("/admin-role-manage")
    public ModelAndView roleListManage(){
        ModelAndView modelAndView = this.getModelAndView();
        String viewName = "login";
        if(JurisdictionUtil.isValid()){
            //通过用户roleId获取btn_rights
            Object attribute = this.getRequest().getSession().getAttribute(ConsoleConstant.BTNRIGHTS);
            List<PageData> buttonList = (List<PageData>) JSONArray.parse(attribute.toString());
            viewName = "admin/admin-role-manage";
            modelAndView.addObject("buttons", buttonList);
        }
        modelAndView.setViewName(viewName);
        return modelAndView;
    }



    /**
     * 角色分配界面
     * @return
     */
    @RequestMapping("/admin-role-assign/{rights}/{id}")
    public ModelAndView adminRoleAssign(@PathVariable("rights") String rights,@PathVariable("id") Integer id){
        ModelAndView modelAndView = this.getModelAndView();
        modelAndView.addObject("gorights",rights);
        modelAndView.addObject("role_id",id);
        modelAndView.setViewName("admin/admin-role-assign");
        return modelAndView;
    }


}
